package PACKAGE_NAME;

import java.util.ArrayList;
import java.util.List;

/**
 * 奶茶的抽象类，定义了奶茶的基本属性和操作
 */
public abstract class MilkTea {
    // 定义奶茶的基本属性
    private String name;
    private boolean withMilk;
    private int sweetnessLevel;
    private List<String> addOns;

    /**
     * 构造方法，用于初始化奶茶的名称、是否加奶以及甜度等级
     *
     * @param name        奶茶名称
     * @param withMilk    是否加奶
     * @param sweetnessLevel 甜度等级，范围为0到10
     * @throws IllegalArgumentException 如果名称为空或者甜度等级不在有效范围内
     */
    public MilkTea(String name, boolean withMilk, int sweetnessLevel) throws IllegalArgumentException {
        if (name == null || name.trim().isEmpty()) {
            throw new IllegalArgumentException("Name cannot be null or empty.");
        }
        if (sweetnessLevel < 0 || sweetnessLevel > 10) {
            throw new IllegalArgumentException("Sweetness level must be between 0 and 10.");
        }
        this.name = name;
        this.withMilk = withMilk;
        this.sweetnessLevel = sweetnessLevel;
        this.addOns = new ArrayList<>();
    }

    /**
     * 抽象方法，用于定义制作奶茶的具体步骤
     */
    public abstract void prepare();

    /**
     * 获取奶茶名称
     *
     * @return 奶茶名称
     */
    public String getName() {
        return name;
    }

    /**
     * 设置奶茶名称
     *
     * @param name 奶茶名称
     * @throws IllegalArgumentException 如果名称为空
     */
    public synchronized void setName(String name) {
        if (name == null || name.trim().isEmpty()) {
            throw new IllegalArgumentException("Name cannot be null or empty.");
        }
        this.name = name;
    }

    /**
     * 获取是否加奶
     *
     * @return 是否加奶
     */
    public boolean isWithMilk() {
        return withMilk;
    }

    /**
     * 设置是否加奶
     *
     * @param withMilk 是否加奶
     */
    public synchronized void setWithMilk(boolean withMilk) {
        this.withMilk = withMilk;
    }

    /**
     * 获取甜度等级
     *
     * @return 甜度等级
     */
    public int getSweetnessLevel() {
        return sweetnessLevel;
    }

    /**
     * 设置甜度等级
     *
     * @param sweetnessLevel 甜度等级，范围为0到10
     * @throws IllegalArgumentException 如果甜度等级不在有效范围内
     */
    public synchronized void setSweetnessLevel(int sweetnessLevel) {
        if (sweetnessLevel < 0 || sweetnessLevel > 10) {
            throw new IllegalArgumentException("Sweetness level must be between 0 and 10.");
        }
        this.sweetnessLevel = sweetnessLevel;
    }

    /**
     * 获取小料列表
     *
     * @return 小料列表
     */
    public List<String> getAddOns() {
        return addOns;
    }

    /**
     * 添加小料
     *
     * @param addOn 小料名称
     * @throws IllegalArgumentException 如果小料名称为空
     */
    public synchronized void addAddOn(String addOn) {
        if (addOn == null || addOn.trim().isEmpty()) {
            throw new IllegalArgumentException("Add-on cannot be null or empty.");
        }
        addOns.add(addOn);
    }

    /**
     * 移除小料
     *
     * @param addOn 小料名称
     * @throws IllegalArgumentException 如果小料名称为空
     */
    public synchronized void removeAddOn(String addOn) {
        if (addOn == null || addOn.trim().isEmpty()) {
            throw new IllegalArgumentException("Add-on cannot be null or empty.");
        }
        addOns.remove(addOn);
    }
}
